<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>我的挂号详情 - 医院挂号系统</title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <link rel="stylesheet" href="css/bootstrap.min.css">

    <link rel="stylesheet" href="css/list.css">
    <script type="text/javascript" src="js/jquery.min.js"></script>
    <script type="text/javascript" src="js/bootstrap.min.js"></script>
    <script src="js/jq-paginator.js"></script>

    <style>
        /* 导航栏 */
        .nav {
            background: #fff;
            border-bottom: 1px solid #e9ecef;
            padding: 0.75rem 2rem;
            box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
        }

        .nav-logo {
            height: 40px;
            margin-right: 1rem;
        }

        .nav-link-custom {
            color: #0d6efd;
            font-weight: 500;
            padding: 0.5rem 1rem;
            transition: all 0.2s;
        }

        .nav-link-custom:hover {
            background-color: #f8f9fa;
            border-radius: 0.375rem;
        }

        /* 用户下拉菜单 */
        .user-dropdown {
            position: relative;
            cursor: pointer;
        }

        .user-dropdown-menu {
            display: none;
            position: absolute;
            right: 0;
            top: 40px;
            background: #fff;
            border: 1px solid #ddd;
            border-radius: 0.375rem;
            box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.1);
            z-index: 100;
            min-width: 150px;
        }

        .user-dropdown:hover .user-dropdown-menu,
        .user-dropdown.active .user-dropdown-menu {
            display: block;
        }

        .user-dropdown-item {
            display: block;
            padding: 0.5rem 1rem;
            color: #212529;
            text-decoration: none;
        }

        .user-dropdown-item:hover {
            background-color: #f8f9fa;
        }

        /* 主体内容 */
        .main-container {
            padding: 2rem;
            max-width: 1400px;
            margin: 0 auto;
        }

        .card {
            border: none;
            box-shadow: 0 0.125rem 0.5rem rgba(0, 0, 0, 0.05);
            border-radius: 0.75rem;
            overflow: hidden;
        }

        .table-responsive {
            border-radius: 0.5rem;
        }

        .action-buttons .btn {
            margin: 0 0.2rem;
            padding: 0.4rem 0.6rem;
            font-size: 0.875rem;
        }

        #pageContainer {
            margin: 1rem 0;
        }

        @media (max-width: 768px) {
            .nav {
                flex-direction: column;
                align-items: flex-start;
                padding: 1rem;
            }

            .user-dropdown {
                margin-top: 0.5rem;
            }
        }
        /* 导航栏样式 */
        .nav {
            width: 100%;
            display: flex;
            align-items: center;
            padding: 15px 50px;
            background: white;
            box-shadow: 0 2px 15px rgba(0, 0, 0, 0.08);
            position: relative;
            z-index: 10;
        }

        .nav-logo {
            height: 50px;
            width: 50px;
            border-radius: 50%;
            background: linear-gradient(135deg, #0d6efd 0%, #0b5ed7 100%);
            display: flex;
            align-items: center;
            justify-content: center;
            color: white;
            font-size: 24px;
            font-weight: bold;
            margin-right: 15px;
            box-shadow: 0 3px 10px rgba(13, 110, 253, 0.3);
        }

        .nav-title {
            color: #0d6efd;
            font-size: 1.5rem;
            font-weight: 700;
            letter-spacing: 0.5px;
        }

        .nav-links {
            display: flex;
            align-items: center;
            margin-left: auto;
            gap: 15px;
        }

        .nav-link-custom {
            display: flex;
            align-items: center;
            padding: 8px 16px;
            color: #555;
            text-decoration: none;
            font-weight: 500;
            border-radius: 6px;
            transition: all 0.3s ease;
        }

        .nav-link-custom i {
            margin-right: 6px;
            font-size: 1rem;
            transition: transform 0.3s ease;
        }

        .nav-link-custom:hover {
            background: rgba(13, 110, 253, 0.08);
            color: #0d6efd;
        }

        .nav-link-custom:hover i {
            transform: scale(1.1);
        }

        .user-dropdown {
            position: relative;
            margin-left: 10px;
        }

        .user-info {
            display: flex;
            align-items: center;
            padding: 8px 16px;
            color: #555;
            cursor: pointer;
            border-radius: 6px;
            transition: all 0.3s ease;
        }

        .user-info:hover {
            background: rgba(13, 110, 253, 0.08);
            color: #0d6efd;
        }

        .user-info i {
            margin-right: 8px;
            font-size: 1.2rem;
        }

        .user-dropdown-menu {
            position: absolute;
            top: 100%;
            right: 0;
            width: 200px;
            background: white;
            border-radius: 8px;
            box-shadow: 0 5px 20px rgba(0, 0, 0, 0.1);
            padding: 10px 0;
            margin-top: 5px;
            opacity: 0;
            visibility: hidden;
            transform: translateY(10px);
            transition: all 0.3s ease;
            z-index: 1000;
        }

        .user-dropdown:hover .user-dropdown-menu {
            opacity: 1;
            visibility: visible;
            transform: translateY(0);
        }

        .user-dropdown-menu::before {
            content: '';
            position: absolute;
            top: -8px;
            right: 20px;
            width: 16px;
            height: 16px;
            background: white;
            transform: rotate(45deg);
        }

        .user-dropdown-item {
            display: flex;
            align-items: center;
            padding: 10px 20px;
            color: #333;
            text-decoration: none;
            font-weight: 500;
            transition: all 0.2s ease;
        }

        .user-dropdown-item i {
            margin-right: 10px;
            color: #0d6efd;
            font-size: 1rem;
        }

        .user-dropdown-item:hover {
            background: #f0f7ff;
            color: #0d6efd;
        }
    </style>
</head>
<body>

<nav class="nav">
    <div class="nav-logo">
        <i class="bi bi-heart-pulse"></i>
    </div>
    <span class="nav-title">医院挂号系统</span>

    <div class="nav-links">
        <a class="nav-link-custom" onclick="zy()">
            <i class="bi bi-house-door"></i>主页
        </a>


        <div class="user-dropdown">
            <div class="user-info">
                <i class="bi bi-person-circle"></i>
                <span>当前用户</span>
            </div>

            <div class="user-dropdown-menu">
                <!--                <a class="user-dropdown-item" href="#">-->
                <!--                    <i class="bi bi-person-badge"></i>个人资料-->
                <!--                </a>-->
                <a class="user-dropdown-item" onclick="wdgh()">
                    <i class="bi bi-calendar-check"></i>我的挂号
                </a>
                <a class="user-dropdown-item" onclick="tc()">
                    <i class="bi bi-box-arrow-right"></i>退出登录
                </a>
            </div>
        </div>
    </div>
</nav>

<!-- 主体内容 -->
<div class="main-container">
    <h2 class="mb-4">我的挂号记录</h2>

    <!-- 筛选区域 -->
    <div class="card mb-4">
        <div class="card-body d-flex flex-wrap justify-content-between align-items-center">
            <div class="mb-2 mb-md-0 d-flex gap-2">
                <select class="form-select" id="statusFilter">
                    <option value="">全部状态</option>
                    <option value="0">预约中</option>
                    <option value="1">已完成</option>
                    <option value="2">已过期</option>

                </select>
                <button class="btn btn-outline-primary" onclick="filterAppointments()">
                    <i class="bi bi-funnel"></i> 筛选
                </button>
            </div>
            <div class="input-group w-25">
                <input type="date" class="form-control" id="dateFilter">
                <button class="btn btn-outline-secondary" type="button" onclick="searchByDate()">
                    <i class="bi bi-calendar-event">查询</i>
                </button>
            </div>
        </div>
    </div>

    <!-- 数据表格 -->
    <div class="card">
        <div class="card-body">
            <div class="table-responsive">
                <table class="table table-hover align-middle">
                    <thead class="table-light">
                    <tr>
                        <td>挂号ID</td>
                        <td>医生姓名</td>
                        <td>科室</td>
                        <td>预约日期</td>
                        <td>创建时间</td>
                        <td>状态</td>
                        <td>操作</td>
                    </tr>
                    </thead>
                    <tbody id="tableBody">
                    <!-- 数据行动态填充 -->
                    </tbody>
                </table>
            </div>

            <!-- 分页组件 -->
            <div class="d-flex justify-content-center mt-3">
                <ul id="pageContainer" class="pagination"></ul>
            </div>
        </div>
    </div>
</div>

<!-- 脚本文件 -->
<script src="js/bootstrap.bundle.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/jq-paginator.js"></script>
<script>

    getList()
    function getList() {
        $.ajax({
            type: "get",
            url: "relation/getAll"+location.search,

            success: function(result) {
                if (result) {
                    var html = "";
                    for (var relation of result) {
                        html += '<tr>';
                        // html += '<td><input type="checkbox" name="selectBook" value="'+relation.relationId+'" class="relation-select"/></td>';
                        html += '<td>'+relation.relationId+'</td>';
                        html += '<td>'+relation.doctorName+'</td>';
                        html += '<td>'+relation.departmentName+'</td>';
                        html += '<td>'+relation.appointmentDate+'</td>';
                        html += '<td>'+relation.createTime+'</td>';
                        html += '<td>'+relation.statusZT+'</td>';
                        html += '<td>';
                        html += '<div class="op">';
                        // html += '<a href="update.html?id='+relation.relationId+'">修改 </a>';
                        html += '<a href="javascript:void(0)" onClick="deleteRelation('+relation.relationId+')">删除</a>';
                        html += '</div>';
                        html += '</td>'; // 修正闭合标签
                        html += '</tr>';
                    }
                    $("tbody").html(html);
                }
            },
            error: function(error) {
                console.log(error);
                if(error.status == 401) {
                    alert("未授权，请重新登录");
                    location.href = "login.html";
                } else {
                    alert("加载数据时发生错误，请稍后再试");
                }
            }
        });
    }

    function searchByDate(){
        $.ajax({
            type: "get",
            url: "relation/getByData"+location.search,
            data:{
                appointmentDate:$("#dateFilter").val(),
            },

            success: function(result) {
                if (result) {
                    var html = "";
                    for (var relation of result) {
                        html += '<tr>';
                        // html += '<td><input type="checkbox" name="selectBook" value="'+relation.relationId+'" class="relation-select"/></td>';
                        html += '<td>'+relation.relationId+'</td>';
                        html += '<td>'+relation.doctorName+'</td>';
                        html += '<td>'+relation.departmentName+'</td>';
                        html += '<td>'+relation.appointmentDate+'</td>';
                        html += '<td>'+relation.createTime+'</td>';
                        html += '<td>'+relation.statusZT+'</td>';
                        html += '<td>';
                        html += '<div class="op">';
                        // html += '<a href="update.html?id='+relation.relationId+'">修改 </a>';
                        html += '<a href="javascript:void(0)" onClick="deleteRelation('+relation.relationId+')">删除</a>';
                        html += '</div>';
                        html += '</td>'; // 修正闭合标签
                        html += '</tr>';
                    }
                    $("tbody").html(html);
                }
            },
            error: function(error) {
                console.log(error);
                if(error.status == 401) {
                    alert("未授权，请重新登录");
                    location.href = "login.html";
                } else {
                    alert("加载数据时发生错误，请稍后再试");
                }
            }
        });
    }

    function wdgh(){
        location.href = "list.html"+location.search;
    }

    function tc(){
        location.href = "gh_login.html";
    }

    function zy(){
        location.href = "home.html"+location.search;
    }


    function filterAppointments(){
        var status1 = $("#statusFilter").val();
        console.log(status1)
        if(status1===""){
            getList();
            return;
        }

        $.ajax({
            type: "get",
            url: "relation/getByStatus"+location.search,
            data:{
              status: $("#statusFilter").val()
            },

            success: function(result) {
                if (result) {
                    var html = "";
                    for (var relation of result) {
                        html += '<tr>';
                        // html += '<td><input type="checkbox" name="selectBook" value="'+relation.relationId+'" class="relation-select"/></td>';
                        html += '<td>'+relation.relationId+'</td>';
                        html += '<td>'+relation.doctorName+'</td>';
                        html += '<td>'+relation.departmentName+'</td>';
                        html += '<td>'+relation.appointmentDate+'</td>';
                        html += '<td>'+relation.createTime+'</td>';
                        html += '<td>'+relation.statusZT+'</td>';
                        html += '<td>';
                        html += '<div class="op">';
                        // html += '<a href="update.html?id='+relation.relationId+'">修改 </a>';
                        html += '<a href="javascript:void(0)" onClick="deleteRelation('+relation.relationId+')">删除</a>';
                        html += '</div>';
                        html += '</td>'; // 修正闭合标签
                        html += '</tr>';
                    }
                    $("tbody").html(html);
                }
            },
            error: function(error) {
                console.log(error);
                if(error.status == 401) {
                    alert("未授权，请重新登录");
                    location.href = "login.html";
                } else {
                    alert("加载数据时发生错误，请稍后再试");
                }
            }
        });
    }

    function deleteRelation(id) {
        if (confirm("确定要删除吗？")) {
            // 实际删除请求逻辑
            $.ajax({
                type:"post",
                url: "relation/deleteRelation?relationId="+id,
                success: function() {
                    alert("删除成功");
                    getList(); // 刷新数据
                },
                error: function() {
                    alert("删除失败，请重试");
                }
            });
        }
    }
</script>
</body>
</html>